//
//  BsTableView.m
//  Demo
//
//  Created by colawh on 2019/3/18.
//  Copyright © 2019年 colawhdfws. All rights reserved.
//

#import "BsTableView.h"
#import "Header.h"
#import "ItemTableViewCell.h"
#import "LMSNewXianzhiClassDetailModel.h"
#import "DemoHelp.h"
static NSString *const IDE = @"ItemTableViewCell__ide";

@interface BsTableView()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;


@end

@implementation BsTableView

- (instancetype)init{
    if ([super init]) {
        [self configUI];
    }
    return self;
}
- (CGFloat)realHeight{
    
    return _tableView.contentSize.height;
}
- (void)configUI{
    [self addSubview:self.tableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    LMSNewXianzhiClasslectureModel *chapterModel = self.dataSource[section];
    return  chapterModel.children.count;

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *contentView = [UIView new];
    UILabel *lb = [DemoHelp getLbByFont:16];
    lb.textColor = kUIColorFromRGB(0x091522);
    LMSNewXianzhiClasslectureModel *chapterModel = self.dataSource[section];
    lb.text = chapterModel.lecture_title;
    [contentView addSubview:lb];
    [lb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.height.equalTo(contentView);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
    }];
    return contentView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDE forIndexPath:indexPath];
    LMSNewXianzhiClasslectureModel *chapterModel = self.dataSource[indexPath.section];
    NSDictionary *dic = chapterModel.children[indexPath.row];
    NSString *tStr = [NSString stringWithFormat:@"%ld-%ld,测试数据",indexPath.section,indexPath.row];
    [cell setTileStr:dic[@"lecture_title"] detailStr:[NSString stringWithFormat:@"%@",dic[@"lecture_length"]]];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
        _tableView.separatorColor = [UIColor clearColor];
        [_tableView registerClass:[ItemTableViewCell class] forCellReuseIdentifier:IDE];
    }
    return _tableView;
}
@end
